package com.gobang.domain.enums;

/**
 * 游戏结果枚举
 * 
 * @author System
 * @since 1.0.0
 */
public enum GameResult {
    
    /**
     * 五子连珠获胜
     */
    FIVE_IN_ROW("FIVE_IN_ROW", "五子连珠"),
    
    /**
     * 对手认输获胜
     */
    SURRENDER("SURRENDER", "对手认输"),
    
    /**
     * 超时获胜
     */
    TIMEOUT("TIMEOUT", "超时获胜"),
    
    /**
     * 游戏取消
     */
    CANCELLED("CANCELLED", "游戏取消");
    
    private final String code;
    private final String description;
    
    GameResult(String code, String description) {
        this.code = code;
        this.description = description;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;
    }
    
    /**
     * 根据结果码获取枚举
     *
     * @param code 结果码
     * @return 游戏结果枚举
     */
    public static GameResult fromCode(String code) {
        for (GameResult result : GameResult.values()) {
            if (result.getCode().equals(code)) {
                return result;
            }
        }
        throw new IllegalArgumentException("未知的游戏结果码: " + code);
    }
} 